package org.cagui.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.cagui.core.CertificateManager;
import org.cagui.core.KeyStoreManager;


public class GUIG extends JFrame implements ActionListener
{
	JButton bwyj, bnewca,baddca, brem, bkey,bsign;
	JLabel gui,ca;
	
	KeyStoreManager keyStoreManager;
	CertificateManager certManager;
	
	public GUIG() 
     {  
		
		keyStoreManager = new KeyStoreManager();
		certManager = new CertificateManager();
		
		setSize (570,250);
        setTitle ("GUI");
        setLayout(null);
        	
        //Przyciski
        bnewca = new JButton ("New ca.");
        bnewca.setBounds(10, 150, 100, 50);
        add (bnewca);
        bnewca.addActionListener(this);    
        
        baddca = new JButton ("Csr Req.");
        baddca.setBounds(120, 150, 100, 50);
        add(baddca);
        baddca.addActionListener(this);  
        
        brem = new JButton ("Your cert.");
        brem.setBounds(230, 150, 100, 50);
        add(brem);
        brem.addActionListener(this);
        
        bkey = new JButton ("Key st.");
        bkey.setBounds(340, 150, 100, 50);
        add(bkey);
        bkey.addActionListener(this);
        
        bsign = new JButton ("SIGN ST.");
        bsign.setBounds(450, 150, 100, 50);
        //add(bsign);
        bsign.addActionListener(this);
        
        bwyj = new JButton ("Exit");
        bwyj.setBounds(450, 150, 100, 50);
        add(bwyj);
        bwyj.addActionListener(this);
        
        
        //Nag��wek
        gui = new JLabel ("USER GUI");
        gui.setBounds(235, 5, 100, 50);
        gui.setForeground(Color.ORANGE);
        gui.setFont(new Font("Calibri",Font.PLAIN,25));
        add(gui);
        //Nag��wek
        ca = new JLabel ("CA");
        ca.setBounds(280, 30, 100, 50);
        ca.setForeground(Color.ORANGE);
        ca.setFont(new Font("Calibri",Font.PLAIN,15));
        add(ca);
        
        
	 }

	@Override
	public void actionPerformed(ActionEvent e) 
	{	
		Object z = e.getSource();
		if (z==bnewca)
		{	
			
			new NewCAForm();

		}
		if (z==bwyj)	
		{
			dispose();
		}
		if (z==baddca)
		{
			new CsrReq();
		}
		if (z==brem)
		{
			new Certificates(certManager);
		}
		if (z == bkey)
		{
			new KeyStores(keyStoreManager);
		}
		
	}
	

	

    
	public static void main (String[] args)
	{
		GUIG GUI = new GUIG();
        GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        GUI.setVisible(true);

      
	}

	

	
	
	
}